package lohr.lang.dom;

import java.io.File;
import java.util.ArrayList;

/**
 * A compilation unit is just a closure that has no parameters
 * @author ted.stockwell
 */
public class CompilationUnit extends ClosureLiteral {
	
	private PackageName _packageName;
	private Imports _imports;
	private File _file;

	public CompilationUnit(PackageName packageName, Imports imports, ClosureBody body) {
		super(new ClosureParameterDeclaration(new ArrayList<TypeReference>()), body);
		prependChild(_imports= imports);
		prependChild(_packageName= packageName);
	}

	public PackageName getPackageName() {
		return _packageName;
	}
	
	public Imports getImports() {
		return _imports;
	}
	
	/**
	 * Returns the physical file associated with this compilation unit, if any
	 * @return
	 */
	public File getFile() {
		return _file;
	}
	public void setFile(File file) {
		_file= file;
	}
	
	@Override
	public String toString() {
		String unit= "package "+_packageName.getFullName()+";\n";
		unit+= _imports.toString()+"\n";
		unit+= getClosureBody().toString();
		return unit;
	}

}
